package com.neteast.androidclient.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class MyDBHelp extends SQLiteOpenHelper {

	private static final String DB_NAME = "neteastdb";
	private static final int DB_VERSION = 1;

	public MyDBHelp(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
	
		db.execSQL("CREATE TABLE IF NOT EXISTS accounts"+
				"( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
				"account INTEGER, " +
				"reserve 1 TEXT, " +
				"reserve 2 TEXT, " +
				"reserve 3 TEXT, )");

		
		db.execSQL("CREATE TABLE IF NOT EXISTS contacts"+
				"( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
				"accountId INTEGER, " +
				"serverId INTEGER, " +
				"is_read_only INTEGER NOT NULL DEFAULT 0, " +
				"version INTEGER NOT NULL DEFAULT 1, " +
				"display_name TEXT, " +
				"nickname TEXT, " +
				"sort_key TEXT, " +
				"organization TEXT, " +
				"job TEXT, " +
				"phone TEXT, " +
				"email TEXT, " +
				"photo TEXT, " +
				"has_photo INTEGER NOT NULL DEFAULT 0, " +
				"reserve 1 TEXT, " +
				"reserve 2 TEXT, " +
				"reserve 3 TEXT, " +
				"reserve 4 TEXT, " +
				"reserve 5 TEXT, " +
				"reserve 6 TEXT, " +
				"reserve 7 TEXT )");

		db.execSQL("CREATE TABLE IF NOT EXISTS groups"+
				"( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
				"accountId INTEGER, " +
				"serverId INTEGER, " +
				"is_read_only INTEGER NOT NULL DEFAULT 0, " +
				"title TEXT, " +
				"reserve 1 TEXT, " +
				"reserve 2 TEXT, " +
				"reserve 3 TEXT, " +
				"reserve 4 TEXT, )");

		db.execSQL("CREATE TABLE IF NOT EXISTS datas"+
				"( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
				"mimetype_id INTEGER NOT NULL, " +
				"contact_id INTEGER NOT NULL, " +
				"is_read_only INTEGER NOT NULL DEFAULT 0, " +
				"data1 TEXT, " +
				"data2 TEXT, " +
				"data3 TEXT, " +
				"data4 TEXT, " +
				"data5 TEXT, " +
				"data6 TEXT, " +
				"data7 TEXT, " +
				"data8 TEXT, " +
				"data9 TEXT, " +
				"data10 TEXT, " +
				"data11 TEXT )");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS accounts");
		db.execSQL("DROP TABLE IF EXISTS contacts");
		db.execSQL("DROP TABLE IF EXISTS groups");
		db.execSQL("DROP TABLE IF EXISTS datas");
		onCreate(db);
	}
}
